package com.dsteiner.xelavos.client;

import java.beans.PropertyChangeListener;

import com.dsteiner.widgets.client.PopupOverlayWidget;
import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PopupOverlayModel;
import com.dsteiner.xelavos.client.controller.ContactController;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class ContactWidget extends LazyWidget {

	public static class ContactModel {
		private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
				this);

		public void addPropertyChangeListener(String propertyName,
				PropertyChangeListener listener) {
			propertyChangeSupport.registerPropertyChangeListener(propertyName,
					listener);
		}
	}

	private ContactController contactController = new ContactController();
	private final ContactModel contactModel;

	public ContactWidget(ContactModel contactModel) {
		this.contactModel = contactModel;
	}

	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		PopupOverlayModel popupOverlayModel = new PopupOverlayModel();
		PopupOverlayWidget popupOverlayWidget = new PopupOverlayWidget(popupOverlayModel);
		HTMLExt infoHtml = new HTMLExt("Applicacion de Xelavos creado por<br/>" +
				"<a href=\"mailto:dominik.j.steiner@xelavos.com\">" +
				"Dominik Julian Steiner</a>");
		HTMLExt contactLink = new HTMLExt(
				"<a href=\"javascript:void(0);\">contacto</a>");
		popupOverlayModel.setContentWidget(infoHtml);
		
		mainPanel.add(contactLink);
		setStyleName(XelavosResources.INSTANCE.css().contactWidget());

		contactController.registerContactWidget(this);
		contactController.registerContactModel(contactModel);
		contactController.registerContactLink(contactLink);
		contactController.registerPopupOverlayModel(popupOverlayModel);
		return mainPanel;
	}

}